import { InputQuestion, QuestionBase, SelectQuestion, RadioQuestion, TextQuestion } from '@/components/public-template';
import { TextTable } from '@/components/public-template';
import { TableBase } from '@/components/public-template';
import { Api as ApiArchives } from '@/config/api/archives';
import { Api as ApiSystem } from '@/config/api/system';
import { Api as ApiResource } from '@/config/api/resourceFileInfo';
import { changeByte, filterTable } from '@/utils/common';
import { regExp } from '@/utils/regExp';

class IndexService {
  getQuestions() {
    const questions: QuestionBase<any>[] = [
      new TextQuestion({
        key: 'billCode',
        label: '单据编号',
        value: null
      }),
      new TextQuestion({
        key: 'creator',
        hide: true,
        value: null
      }),
      new TextQuestion({
        key: 'creatorName',
        label: '创建人',
        value: null
      }),
      new TextQuestion({
        key: 'department',
        hide: true,
        value: null
      }),
      new TextQuestion({
        key: 'departmentName',
        label: '创建部门',
        value: null
      }),
      new TextQuestion({
        key: 'createdTime',
        label: '创建时间',
        value: null
      }),
      new TextQuestion({
        key: 'expirationReminder',
        label: '到期提醒时间',
        value: null
      })
    ];
    return questions;
  }
  getFileQuestions() {
    const questions: QuestionBase<any>[] = [
      new SelectQuestion({
        key: 'boxIds',
        label: '档案盒',
        required: true,
        prompt: '请选择',
        // type: 'search',
        value: [],
        state: {
          name: 'migrationTable',
          mode: 'multiple',
          url: ApiArchives.boxPage,
          protType: 'post',
          nameKey: 'code',
          nameValue: 'id',
          optionFilterProp: 'label',
          params: {
            status: [2],
            pageSize: 999,
            pageNumber: 1
          }
        }
      })
    ];
    return questions;
  }
  getViewFileQuestions() {
    const questions: QuestionBase<any>[] = [
      new TextQuestion({
        key: 'archivesFileBox',
        label: '档案盒',
        value: null
      })
    ];
    return questions;
  }
  getMsgQuestions() {
    const questions: QuestionBase<any>[] = [
      new InputQuestion({
        key: 'reason',
        label: '迁移原因',
        required: true,
        prompt: '请输入',
        value: null
      }),
      new SelectQuestion({
        key: 'targetAdminBy',
        label: '目标档案管理员',
        required: true,
        prompt: '请选择',
        value: null,
        state: {
          url: ApiSystem.subjectListSimple,
          protType: 'post',
          nameKey: 'nickName',
          nameValue: 'id',
          showSearch: true,
          optionFilterProp: 'label'
        }
      }),
      new InputQuestion({
        key: 'remark',
        label: '备注',
        type: 'textarea',
        value: null,
        reg: regExp.len100,
        prompt: '长度不可超过100个字符'
      })
    ];
    return questions;
  }
  getViewMsgQuestions() {
    const questions: QuestionBase<any>[] = [
      new TextQuestion({
        key: 'reason',
        label: '迁移原因',
        value: null
      }),
      new TextQuestion({
        key: 'targetAdminByName',
        label: '目标档案管理员',
        value: null
      }),
      new TextQuestion({
        key: 'remark',
        label: '备注',
        value: null
      })
    ];
    return questions;
  }
  getCommentQuestions({ showType }) {
    const questions: QuestionBase<any>[] = [
      showType == 'AUDIT'
        ? new RadioQuestion({
            key: 'applyResult',
            label: '意见',
            required: true,
            prompt: '请选择',
            value: 1,
            options: [
              {
                label: '通过',
                value: 1
              },
              {
                label: '驳回',
                value: 2
              }
            ]
          })
        : new RadioQuestion({
            key: 'isReceive',
            label: '意见',
            required: true,
            prompt: '请选择',
            value: true,
            options: [
              {
                label: '通过',
                value: true
              },
              {
                label: '驳回',
                value: false
              }
            ]
          }),
      new InputQuestion({
        key: 'remark',
        label: '备注',
        value: null
      })
    ];
    return questions;
  }
  getTables({ showType }) {
    const tables: TableBase<any>[] = [
      new TextTable({
        key: 'num',
        value: '序号',
        type: 'index'
      }),
      new TextTable({
        key: 'boxCode',
        value: '档案盒'
      }),
      new TextTable({
        key: 'storageLocationCode',
        value: '原存放地点'
      }),
      new TextTable({
        key: 'type',
        value: '载体形式',
        type: 'dictionary',
        state: {
          filterName: 'CARRIER_TYPE'
        }
      }),
      new TextTable({
        key: 'name',
        value: '文件名称'
      }),
      new TextTable({
        key: 'code',
        value: '文件编码'
      }),
      new TextTable({
        key: 'fileCode',
        value: '文件号'
      }),
      new TextTable({
        key: 'filePages',
        value: '文件页数'
      }),
      new TextTable({
        key: 'filesBoxCode',
        value: '档案编码'
      }),
      new TextTable({
        key: 'filesTypeName',
        value: '档案类型'
      }),
      new TextTable({
        key: 'secretLevel',
        value: '保密等级',
        type: 'dictionary',
        state: {
          filterName: 'SECRET_LEVEL'
        }
      }),
      new TextTable({
        key: 'fromDate',
        value: '形成时间'
      }),
      new TextTable({
        key: 'chargeUserIdName',
        value: '责任者'
      }),
      new TextTable({
        key: 'retentionPeriodDate',
        value: '保管期限',
        type: 'dictionary',
        state: {
          filterName: 'DMS_ARCHIVES_FILE_LIST_RETENTION_PERIOD_DATE'
        }
      }),
      new TextTable({
        key: 'toDepartmentName',
        value: '归档部门'
      }),
      new TextTable({
        key: 'toDate',
        value: '归档时间'
      }),
      new TextTable({
        key: 'remark',
        value: '说明'
      }),
      showType == 'RECEIVE'
        ? new TextTable({
            key: 'isReceive',
            value: '是否接收',
            type: 'slot',
            state: {
              slotName: 'isReceive'
            }
          })
        : new TextTable({
            key: 'isReceive',
            value: '是否接收',
            type: 'dictionary',
            state: {
              filterName: 'YES_OR_NO'
            }
          }),
      new TextTable({
        key: 'actions',
        value: '操作',
        handle: [
          {
            type: 'local',
            text: '预览',
            class: 'text-primary',
            state: {
              name: 'LOCAL_PREVIEW'
            }
          }
        ]
      })
    ];
    const showConfig = {
      isReceive: ['RECEIVE', 'CONFIRM', 'VIEW'].includes(showType)
    };
    return filterTable(tables, showConfig);
  }
  getReceiveTables({ showType }) {
    const tables: TableBase<any>[] = [
      new TextTable({
        key: 'num',
        value: '序号',
        type: 'index'
      }),
      new TextTable({
        key: 'name',
        value: '附件名称',
        type: 'router',
        state: {
          type: 'local'
        }
      }),
      new TextTable({
        key: 'size',
        value: '大小',
        type: 'custom',
        columns: {
          customRender: (data: any) => {
            return changeByte(data.value);
          }
        }
      }),
      new TextTable({
        key: 'createdTime',
        value: '上传时间'
      }),
      new TextTable({
        key: 'actions',
        value: '操作',
        handle: [
          {
            type: 'local',
            text: '删除',
            class: 'text-primary',
            url: '/url',
            params: [{ id: 'id' }],
            state: {
              type: 'delete'
            }
          }
        ]
      })
    ];
    const showConfig = {
      actions: showType == 'RECEIVE'
    };
    return filterTable(tables, showConfig);
  }
  getReceiveIcons({ showType, handleReceiveImport }) {
    const icons: TableBase<any>[] =
      showType == 'RECEIVE'
        ? [
            new TextTable({
              key: 'upload',
              value: '导入',
              type: 'primary',
              class: 'icon-upload',
              state: {
                url: ApiResource.resourceUploadFiles,
                downloadRule: '支持Word、PPT、Excel、PDF、txt、FASTA、XML、视频、音频、照片、驱动文件等文件格式',
                callback: (data) => {
                  handleReceiveImport && handleReceiveImport(data);
                }
              }
            })
          ]
        : [];
    return icons;
  }
  getPositionTables({ showType }) {
    const tables: TableBase<any>[] = [
      new TextTable({
        key: 'num',
        value: '序号',
        type: 'index'
      }),
      showType == 'CONFIRM'
        ? new TextTable({
            key: 'targetLocation',
            value: '新存放地点',
            type: 'slot',
            state: {
              slotName: 'targetLocation',
              slotTitleName: 'targetLocationTitle'
            }
          })
        : new TextTable({
            key: 'targetLocationCode',
            value: '新存放地点'
          }),
      new TextTable({
        key: 'archiveBoxCode',
        value: '档案盒'
      }),
      new TextTable({
        key: 'sourceLocationCode',
        value: '原存放地点'
      })
    ];
    return tables;
  }
}

export default new IndexService();
